package cn.itcast.hotel.listen;

import cn.itcast.hotel.constants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author mrchen
 * @date 2022/2/18 14:32
 */
@Component
@Slf4j
public class HotelListener {
    @Autowired
    IHotelService iHotelService;



    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void handleInsertMsg(Long id){
        log.info("接收到 insert队列消息  ，消息内容==> {}",id);
        // 新增文档
        iHotelService.addDocument(id);
    }

    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void handleDeleteMsg(Long id){
        log.info("接收到 delete队列消息  ，消息内容==> {}",id);
        // 删除文档
        iHotelService.deleteDocument(id);
    }

}
